home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_400
/
436_01
/
inutil.c
< prev
next >
Wrap
Text File
|
1994-10-07
|
6KB
|
195 lines
/*************************************************************************
Source file: INUTIL.C
INCON utility routines. All routines in this module are public,
and may be called directly by programs that link INCON.LIB.
Compiler: Borland Turbo C 2.01
INCON source files and the object and library files created from
them are:
Copyright (c) 1993-94, Richard Zigler.
You may freely distribute unmodified source, object, and library
files, and incorporate them into your own non-commercial software,
provided that this paragraph and the program name and copyright
strings defined in INCON.C are included in all copies.
*************************************************************************/
#include <dos.h> /* geninterrupt() */
#include "indefs.h" /* globals and definitions */
#include "indecl.h" /* public utility routines */
/************************************************************************/
/* Cursor handling. Call with OFF argument prior to ON, and with */
/* SAVE prior to RESTORE. */
void pascal Cursor( short CurSwitch )
{
switch ( CurSwitch )
{
static short cshape, cpos; /* cursor shape, position */
case OFF: /* turn off the cursor */
_AH = CUR_GET; /* get cursor shape/position */
_BH = ACT_PAGE; /* on video page 0 */
geninterrupt( BIOS_VIDEO );
cshape = _CX; /* save shape */
_AH = CUR_SIZE;
_CX |= CUR_OFF; /* set bit 5 in CH */
geninterrupt( BIOS_VIDEO );
break;
case ON: /* turn cursor back on */
_AH = CUR_SIZE;
_CX = cshape & ~CUR_OFF; /* clear bit 5 in CH */
geninterrupt( BIOS_VIDEO );
break;
case SAVE: /* save cursor position */
_AH = CUR_GET;
_BH = ACT_PAGE;
geninterrupt( BIOS_VIDEO );
cpos = _DX;
break;
case RESTORE: /* restore cursor position */
_AH = CUR_SET;
_BH = ACT_PAGE;
_DX = cpos;
geninterrupt( BIOS_VIDEO );
break;
default:
break;
}
} /**** Cursor() ****/
/************************************************************************/
/* GetCursor() */
/* Get absolute screen coordinates. */
void pascal GetCursor( short * Row, short * Col )
{
_AH = CUR_GET;
_BH = 0;
geninterrupt( BIOS_VIDEO );
*Row = _DH;
*Col = _DL;
}
/************************************************************************/
/* GetVideoAttr() */
/* Get video attribute at cursor on current page. */
int pascal GetVideoAttr( void )
{
_AH = GET_ATTR;
_BH = 0;
geninterrupt( BIOS_VIDEO );
return ( _AH );
}
/************************************************************************/
/* PutCursor() */
/* Place cursor at row and col on video page 0. */
void pascal PutCursor( short Row, short Col )
{
_AH = CUR_SET;
_BH = 0;
_DH = Row;
_DL = Col;
geninterrupt( BIOS_VIDEO );
}
/************************************************************************/
/* WordLeft() */
/* Scan string left from current position to first occurence of */
/* search character. Return index to character following search */
/* character. */
int pascal WordLeft
(
register int Pos, /* current index */
char far *String, /* string to scan */
char SearchChar /* search character */
)
{
/****
Scan left while the previous character is the search
character. The prefix-decrement of Pos is necessary
to obtain the previous character. If the cursor is
within a word, the test for SearchChar fails immedi-
ately; if it is at the beginning or between words,
the test fails at the end of the previous word.
****/
while ( Pos >= 0 && String[--Pos] == SearchChar )
;
/****
Continue to scan left while the previous character is not
the search character. In the first case noted above, the
test fails at the beginning of the word; in the second it
fails at the beginning of the previous word.
****/
while ( Pos >= 0 && String[--Pos] != SearchChar )
;
/****
The prefix-decrement of Pos leaves it pointing at the
character previous to the target, so it is incremented
before being returned.
****/
return( ++Pos );
}
/************************************************************************/
/* WordRight() */
/* This operation is the mirror image of WordLeft(); the scan is */
/* bounded by the end-of-string null byte. */
int pascal WordRight
(
register int Pos, /* current index */
char far *String, /* string to scan */
char SearchChar /* search character */
)
{
while ( String[Pos] && String[++Pos] != SearchChar ) ;
while ( String[Pos] && String[++Pos] == SearchChar ) ;
return( Pos );
}
/************************************************************************/
/* WriteMany() */
/* Writes character and attribute combination at current cursor */
/* position; repeats Num times. The cursor is not moved. */
void pascal WriteMany
(
BYTE Chr, /* ASCII character */
int Attr, /* video attribute */
int Num /* times to write Attr/ch */
)
{
_AH = WRITE_MANY;
_AL = Chr;
_BH = 0;
_BL = (BYTE) Attr;
_CX = Num;
geninterrupt( BIOS_VIDEO );
}
/**** EOF: INUTIL.C ****/